package com.emm.yixun.common.response;

import javax.xml.bind.annotation.XmlRootElement;

/**
 * <p>注释</p>
 *
 */
@XmlRootElement
public class Response<T> extends BaseResult{

    /**
     * 
     */
    private static final long serialVersionUID = -3939832476038601532L;
    
    private T entity;


    public Response(){

    }

    public Response(boolean success){
        super(success);
    }


    public T getEntity() {
        return entity;
    }

    public void setEntity(T entity) {
        this.entity = entity;
    }
    
    public Response<T> success(){
        setSuccess(true);
        return this;
    }
    
    public void success(T t){
        setSuccess(true);
        setEntity(t);
    }
    
    public Response<T> fail(){
        setSuccess(false);
        return this;
    }
    
    public Response<T> fail(String errorcode,String message){
        setSuccess(false);
        setErrorCode(errorcode);
        setResultMessage(message);
        return this;
    }

    public static class ResponseBuilder{

        private Response response;


        private ResponseBuilder(boolean success){
            this.response = new Response(success);
        }

        public Response build(){
            return response;
        }

        public ResponseBuilder setErrorCode(String errorCode){
            response.setErrorCode(errorCode);
            return this;
        }
        public ResponseBuilder setResultMessage(String resultMessage) {
            response.setResultMessage(resultMessage);
            return this;
        }

        public ResponseBuilder setEntity(Object entity) {
            response.setEntity(entity);
            return this;
        }

        public static ResponseBuilder success(){
            return new ResponseBuilder(true);
        }

        public static ResponseBuilder error(){
            return new ResponseBuilder(false);
        }

    }

 
}
